package com.excesys.exsecs.admin.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.excesys.exsecs.admin.api.entity.SysBaseInfo;
import com.excesys.exsecs.admin.service.SysBaseInfoService;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.log.annotation.SysLog;
import org.springframework.security.access.prepost.PreAuthorize;
import com.excesys.exsecs.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 系统基本信息表
 *
 * @author lxc
 * @date 2024-10-11 09:48:34
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysbase" )
@Tag(description = "sysBaseInfo" , name = "系统基本信息表管理" )
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class SysBaseInfoController {

    private final SysBaseInfoService sysBaseInfoService;


    /**
     * 通过id查询系统基本信息表
     * @return R
     */
    @Operation(summary = "通过id查询" , description = "通过id查询" )
    @GetMapping("/getBase" )
    @PreAuthorize("@pms.hasPermission('sys_sysBaseInfo_view')" )
    public R getBase() {
        return R.ok(this.sysBaseInfoService.getOne(Wrappers.<SysBaseInfo>lambdaQuery()
                .orderByDesc(SysBaseInfo::getUpdateTime).last("LIMIT 1")));
    }

    /**
     * 新增/修改系统基本信息表
     * @param sysBaseInfo 系统基本信息表
     * @return R
     */
    @Operation(summary = "新增/修改系统基本信息表" , description = "新增/修改系统基本信息表" )
    @SysLog("新增/修改系统基本信息表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('sys_sysBaseInfo_add')" )
    public R save(@RequestBody SysBaseInfo sysBaseInfo) {
        return R.ok(sysBaseInfoService.saveOrUpdate(sysBaseInfo));
    }
}